<template>
    <div class="school">
        <button @click="add">点我添加到local</button>
        <button @click="show">点我展示</button>
        <button @click="del">点我删除</button>
        <button @click="delAll">点我删全部</button>
    </div>
</template>

<script>
    export default {
        name: 'SessionStorage',
        data() {
            return {
                person: {
                    name: '周亮',
                    age: 22,
                    project: '前端'
                }
            }
        },
        methods: {
            add() {
                sessionStorage.setItem('person', JSON.stringify(this.person))
            },
            show() {
                const result = sessionStorage.getItem('person');
                console.log(JSON.parse(result));
            },
            del() {
                sessionStorage.removeItem('person')
            },
            delAll() {
                sessionStorage.clear()
            }
        }
    }
</script>

<style scoped>
    .school {
        background-color: skyblue;
        padding: 20px;
    }
</style>